package com.my.easypoi.domain;

import cn.afterturn.easypoi.excel.annotation.*;
import cn.hutool.core.util.ObjectUtil;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

@Data
@AllArgsConstructor
//@RequiredArgsConstructor
@NoArgsConstructor
@ExcelTarget("users")
public class User implements Serializable {
    //name用于设置列名，orderNum是设置列的位置,默认为0
    @Excel(name = "编号",orderNum = "1")
    private String id;
    @Excel(name = "姓名",orderNum = "2")
    private String name;
    @Excel(name="年龄",orderNum = "3")
    private Integer age;
    //format用于设置显示格式，width用于设置列的宽度
    @Excel(name="出生日期",orderNum = "4",format = "yyyy-MM-dd",width = 35.0)
    private Date birth;
    //我们数据库中保存用户状态一般使用1、0等，但是导出到excel需要转换成对应的文字
    //信息，就可以使用replace，显示的文字信息和保存的状态码使用下划线_分隔
    @Excel(name = "用户状态",replace = {"激活_1","禁用_0"})
    private Integer status;
    /*******************************数组*******************************************/
//    @Excel(name = "爱好",orderNum = "5")
    @ExcelIgnore
    private List<String> hobbies;
    @Excel(name = "爱好",orderNum = "5",width = 35.0)
    private String hobbyStr;//这个是拼接用的字符串

    public String getHobbyStr() {
        StringBuilder sb = new StringBuilder();
        if(ObjectUtil.isNotEmpty(hobbies)){
            hobbies.forEach(h -> {
                sb.append(h);
                sb.append("、");
            });
            return sb.substring(0,sb.length()-1).toString();
        }else{
            return null;
        }
    }
    /********************************对象******************************************/
    @ExcelEntity
    private Card card;
    @Excel(name = "图片",width = 20.0,height = 20.0,type = 2,imageType = 1)//type=2表示图片类型
//    @Excel(name = "头像信息",type = 2,savePath = "E:\\IDEA-workspace\\codes\\easypoi_springboot\\src\\main\\resources\\static\\imgs")
    private String photo;

    @ExcelCollection(name = "订单列表",orderNum = "10")
    private List<Order> orders;


    /**************************************************************************/

    public User(String id, String name) {
        this.id = id;
        this.name = name;
    }

    public User(String id, String name, Integer age, Date birth) {
        this.id = id;
        this.name = name;
        this.age = age;
        this.birth = birth;
    }

    public User(String id, String name, String photo) {
        this.id = id;
        this.name = name;
        this.photo = photo;
    }

    public User(String id, String name, Integer age, Date birth, List<Order> orders) {
        this.id = id;
        this.name = name;
        this.age = age;
        this.birth = birth;
        this.orders = orders;
    }
    public User(String id, String name, Integer age, Date birth, Integer status, List<String> hobbies) {
        this.id = id;
        this.name = name;
        this.age = age;
        this.birth = birth;
        this.status = status;
        this.hobbies = hobbies;
    }
    public User(String id, String name, Integer age, Date birth, Integer status, List<String> hobbies, Card card) {
        this.id = id;
        this.name = name;
        this.age = age;
        this.birth = birth;
        this.status = status;
        this.hobbies = hobbies;
        this.card = card;
    }

}
